package com.song.controller.admin;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.song.entity.Borrower;
import com.song.entity.vo.BorrowerApprovalVO;
import com.song.entity.vo.BorrowerDetailVO;
import com.song.result.Result;
import com.song.service.BorrowerService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author Song
 * @since 2025-01-03
 */
@RestController
@RequestMapping("/admin/core/borrower")
public class AdminBorrowerController {

    @Autowired
    private BorrowerService borrowerService;


    // /api/core/borrower/auth/save
    //http://localhost/admin/core/borrower/list/1/10?keyword=

    /*
      url: `/admin/core/borrower/list/${page}/${limit}`,
      method: 'get',
      params: { keyword }

     */

    @ApiOperation("获取借款人分页列表")
    @GetMapping("/list/{page}/{limit}")
    public Result list(
            @ApiParam(value = "当前页码",required = true)
            @PathVariable Long page,
            @ApiParam(value = "每页记录数",required = true)
            @PathVariable Long limit,
            @ApiParam(value = "查询关键字",required = false)
            @RequestParam String keyword

    ){
        //分页了
        Page<Borrower> pageParam = new Page<>(page,limit);

       IPage<Borrower> borrowerIPage= borrowerService.listPage(pageParam,keyword);


        return  Result.ok().data("pageModel",borrowerIPage);
    }

    //http://localhost/admin/core/borrower/show/7

    @ApiOperation("获取借款人信息")
    @GetMapping("/show/{id}")
    public Result show(
            @ApiParam(value = "借款人id",required = true)
            @PathVariable Long id
    ) {
        BorrowerDetailVO vo = borrowerService.getBorrowerDetailVOById(id);

        return Result.ok().data("borrowerDetailVO", vo);

    }

    //
   // http://localhost/admin/core/borrower/approval

    @ApiOperation("借款额度审批")
    @PostMapping("/approval")
    public Result approval(
            @RequestBody BorrowerApprovalVO borrowerApprovalVO
            ) {
       // BorrowerDetailVO vo = borrowerService.getBorrowerDetailVOById(id);
        borrowerService.approval(borrowerApprovalVO);

        return Result.ok().message("审批成功");

    }

}

